﻿/* 
 * LogonOptionsDesign.cs
 * 
 * Author - Ankit Gupta and Gaurav Aggarwal
 * 
 * This file handles component design of Logon Options tab.
 * 
 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using System.Text;
using Microsoft.Win32;

partial class LogonOptionsControl
{
    public DataGridView datagrid = new DataGridView();
    public DataGridViewTextBoxColumn Column1 = new DataGridViewTextBoxColumn();
    public Label autoLoginLabel = new Label();
    public Label reportErrorsLabel = new Label();
    public Label retryEveryLabel = new Label();
    public Label retryEverySecLabel = new Label();
    public Label quitAfterLabel = new Label();
    public Label quitAfterSecLabel = new Label();
    public Label logonScriptLabel = new Label();
    public Label cellsLabel = new Label();
    public Label newDomainLabel = new Label();
    public Label preserveTokensLabel = new Label();
    public Button updateButton = new Button();
    public Button removeButton = new Button();
    public Button addButton = new Button();
    public Button applyButton = new Button();
    public Button cancelButton = new Button();
    public TextBox retryEveryTextBox = new TextBox();
    public TextBox quitAfterTextBox = new TextBox();
    public TextBox logonScriptTextBox = new TextBox();
    public TextBox cellsTextBox = new TextBox();
    public TextBox newDomainTextBox = new TextBox();
    public CheckBox autoLoginCheckBox = new CheckBox();
    public CheckBox reportErrorsCheckBox = new CheckBox();
    public CheckBox preserveTokensCheckBox = new CheckBox();
    public GroupBox grpbox1 = new GroupBox();
    public GroupBox grpbox2 = new GroupBox();
    public GroupBox grpbox3 = new GroupBox();

    RegistryKey selectedDomain;
    public string node;
    RegistryKey serviceParameters = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters", true);
    RegistryKey netprovider = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters", true);

    public LogonOptionsControl()
    {
        RegistryKey domain = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Services\\TransarcAFSDaemon\\NetworkProvider\\Domain\\", true);
        Array a = null;
        if(domain!=null) a = domain.GetSubKeyNames();

        grpbox1.Location = new System.Drawing.Point(240, 10);
        grpbox1.Name = "grpBox1";
        grpbox1.Size = new System.Drawing.Size(330, 300);
        grpbox1.Text = "Logon Options for Default Domain";

        grpbox2.Location = new System.Drawing.Point(250, 60);
        grpbox2.Name = "grpBox2";
        grpbox2.Size = new System.Drawing.Size(300, 125);
        grpbox2.Text = "If automatic login fails...";

        datagrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
        datagrid.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { Column1 });
        datagrid.Rows.Add("Default");
        if (a != null)
        {
            for (int i = 0; i < a.Length; i++)
            {
                datagrid.Rows.Add(a.GetValue(i).ToString());
            }
        }
        datagrid.Location = new System.Drawing.Point(20, 15);
        datagrid.RowHeadersVisible = false;
        datagrid.BackgroundColor = Color.White;
        datagrid.Name = "datagrid";
        datagrid.ReadOnly = true;
        datagrid.Size = new System.Drawing.Size(200, 400);
        datagrid.CurrentCell = datagrid.Rows[0].Cells[0];
        datagrid.Click += new System.EventHandler(datagridView_Click);

        Column1.HeaderText = "Domains";
        Column1.Name = "Column1";
        Column1.Width = 197;

        // Login Automatically
        autoLoginCheckBox.Location = new System.Drawing.Point(250, 30);
        autoLoginCheckBox.Name = "autoLoginCheckBox";
        autoLoginCheckBox.Size = new System.Drawing.Size(15, 20);
        autoLoginCheckBox.Checked = true;

        autoLoginLabel.Location = new System.Drawing.Point(270, 33);
        autoLoginLabel.Name = "autoLoginLabel";
        autoLoginLabel.Size = new System.Drawing.Size(200, 20);
        autoLoginLabel.Text = "Login automatically";

        // Report errors option
        reportErrorsCheckBox.Location = new System.Drawing.Point(260, 85);
        reportErrorsCheckBox.Name = "reportErrorsCheckBox";
        reportErrorsCheckBox.Size = new System.Drawing.Size(15, 20);
        reportErrorsCheckBox.Checked = Convert.ToBoolean((int)netprovider.GetValue("FailLoginsSilently", 0));

        reportErrorsLabel.Location = new System.Drawing.Point(280, 88);
        reportErrorsLabel.Name = "reportErrorsLabel";
        reportErrorsLabel.Size = new System.Drawing.Size(200, 30);
        reportErrorsLabel.Text = "Don't report any errors";

        // Retry every x sec
        retryEveryLabel.Location = new System.Drawing.Point(260, 120);
        retryEveryLabel.Name = "retryEveryLabel";
        retryEveryLabel.Size = new System.Drawing.Size(70, 30);
        retryEveryLabel.Text = "Retry every";

        retryEveryTextBox.Location = new System.Drawing.Point(360, 120);
        retryEveryTextBox.Name = "retryEveryTextBox";
        retryEveryTextBox.Size = new System.Drawing.Size(100, 30);
        retryEveryTextBox.Text = ((int)netprovider.GetValue("LoginRetryInterval", 30)).ToString();

        retryEverySecLabel.Location = new System.Drawing.Point(470, 120);
        retryEverySecLabel.Name = "retryEverySecLabel";
        retryEverySecLabel.Size = new System.Drawing.Size(30, 30);
        retryEverySecLabel.Text = "secs";

        // Quit after x sec
        quitAfterLabel.Location = new System.Drawing.Point(260, 150);
        quitAfterLabel.Name = "quitAfterLabel";
        quitAfterLabel.Size = new System.Drawing.Size(70, 30);
        quitAfterLabel.Text = "Quit after";

        quitAfterTextBox.Location = new System.Drawing.Point(360, 150);
        quitAfterTextBox.Name = "quitAfterTextBox";
        quitAfterTextBox.Size = new System.Drawing.Size(100, 30);
        quitAfterTextBox.Text = ((int)netprovider.GetValue("LoginSleepInterval", 5)).ToString();

        quitAfterSecLabel.Location = new System.Drawing.Point(470, 150);
        quitAfterSecLabel.Name = "quitAfterSecLabel";
        quitAfterSecLabel.Size = new System.Drawing.Size(30, 30);
        quitAfterSecLabel.Text = "secs";

        // Logon Script
        logonScriptLabel.Location = new System.Drawing.Point(270, 200);
        logonScriptLabel.Name = "logonScriptLabel";
        logonScriptLabel.Size = new System.Drawing.Size(70, 30);
        logonScriptLabel.Text = "Logon Script";

        logonScriptTextBox.Location = new System.Drawing.Point(350, 200);
        logonScriptTextBox.Name = "logonScriptTextBox";
        logonScriptTextBox.Size = new System.Drawing.Size(180, 30);
        logonScriptTextBox.Text = netprovider.GetValue("LogonScript", "").ToString();

        // AFS Cells 
        cellsLabel.Location = new System.Drawing.Point(270, 240);
        cellsLabel.Name = "cellsLabel";
        cellsLabel.Size = new System.Drawing.Size(70, 30);
        cellsLabel.Text = "Cells";

        cellsTextBox.Location = new System.Drawing.Point(350, 240);
        cellsTextBox.Name = "cellsTextBox";
        cellsTextBox.Size = new System.Drawing.Size(180, 30);
        cellsTextBox.Text = netprovider.GetValue("TheseCells", "").ToString(); 

        // Update button
        updateButton.Location = new System.Drawing.Point(370, 270);
        updateButton.Name = "updateButton";
        updateButton.Size = new System.Drawing.Size(70, 23);
        updateButton.Text = "Update";
        updateButton.Click += new System.EventHandler(updateButton_Click);

        // Remove button
        removeButton.Location = new System.Drawing.Point(460, 270);
        removeButton.Name = "removeButton";
        removeButton.Size = new System.Drawing.Size(70, 23);
        removeButton.Text = "Remove";
        removeButton.Click += new System.EventHandler(removeButton_Click);

        // Preserve tokens during logoff
        preserveTokensCheckBox.Location = new System.Drawing.Point(250, 330);
        preserveTokensCheckBox.Name = "preserveTokensCheckBox";
        preserveTokensCheckBox.Size = new System.Drawing.Size(15, 20);
        preserveTokensCheckBox.Checked = Convert.ToBoolean((int)serviceParameters.GetValue("RxNoJumbo", 0));

        preserveTokensLabel.Location = new System.Drawing.Point(270, 333);
        preserveTokensLabel.Name = "preserveTokensLabel";
        preserveTokensLabel.Size = new System.Drawing.Size(200, 30);
        preserveTokensLabel.Text = "Preserve tokens during logoff";

        // New domain
        newDomainLabel.Location = new System.Drawing.Point(250, 365);
        newDomainLabel.Name = "newDomainLabel";
        newDomainLabel.Size = new System.Drawing.Size(70, 30);
        newDomainLabel.Text = "New domain";

        newDomainTextBox.Location = new System.Drawing.Point(330, 365);
        newDomainTextBox.Name = "newDomainTextBox";
        newDomainTextBox.Size = new System.Drawing.Size(150, 40);
        newDomainTextBox.Text = "";

        addButton.Location = new System.Drawing.Point(500, 362);
        addButton.Name = "addButton";
        addButton.Size = new System.Drawing.Size(50, 25);
        addButton.Text = "Add";
        addButton.Click += new System.EventHandler(newDomain_Click);

        // Apply button
        applyButton.Location = new System.Drawing.Point(20, 460);
        applyButton.Name = "applyButton";
        applyButton.Size = new System.Drawing.Size(100, 23);
        applyButton.Text = "Apply";
        applyButton.Click += new System.EventHandler(applyButton_Click);

        // Cancel button
        cancelButton.Location = new System.Drawing.Point(140, 460);
        cancelButton.Name = "cancelButton";
        cancelButton.Size = new System.Drawing.Size(100, 23);
        cancelButton.Text = "Cancel";
        cancelButton.Click += new System.EventHandler(cancelButton_Click);
    }
}